<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title>待付款</title>
     <link rel="icon" href="assets/img/favicon.ico">

    <link rel="stylesheet" type="text/css" href="css/webbase.css" />
    <link rel="stylesheet" type="text/css" href="css/pages-seckillOrder.css" />
</head>

<body>

	<!--页面顶部白条条，由js动态加载-->
	<script type="text/javascript" src="plugins/jquery/jquery.min.js"></script>
	<div class="nav-bottom"></div>
    <script type="text/javascript">$(".nav-bottom").load("top.html");</script>

<script type="text/javascript" src="js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	$("#service").hover(function(){
		$(".service").show();
	},function(){
		$(".service").hide();
	});
	$("#shopcar").hover(function(){
		$("#shopcarlist").show();
	},function(){
		$("#shopcarlist").hide();
	});

})
</script>
<script type="text/javascript" src="js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="js/widget/nav.js"></script>
</body>
    <!--header-->
    <div id="account">
        <div class="py-container">
            <div class="yui3-g home">
                <!--左侧列表-->
                <div class="yui3-u-1-6 list">

                    <div class="person-info">
                        <div class="person-photo"><img src="img/_/photo.png" alt=""></div>
                        <div class="person-account">
                            <span class="name">{{user.username}}</span>
                            <span class="safe"><a href="#" @click="logout">退出登录 </a></span>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                     <div class="list-items">
                        <dl>
							<dt><i>·</i> 订单中心</dt>
							<dd ><a href="home-index.html"   >我的订单</a></dd>
							<dd><a href="home-order-pay.html" class="list-active">待付款</a></dd>
							<dd><a href="home-order-send.html"  >待发货</a></dd>
							<dd><a href="home-order-receive.html" >待收货</a></dd>
							<dd><a href="home-order-evaluate.html" >待评价</a></dd>
						</dl>
						<dl>
							<dt><i>·</i> 我的中心</dt>
							<dd><a href="home-person-collect.html">我的收藏</a></dd>
							<dd><a href="home-person-footmark.html">我的足迹</a></dd>
						</dl>
						<dl>
							<dt><i>·</i> 物流消息</dt>
						</dl>
						<dl>
							<dt><i>·</i> 设置</dt>
                            <dd><a href="home-setting-info.html" >个人信息</a></dd>
							<dd><a href="home-setting-address.html"  >地址管理</a></dd>
							<dd><a href="home-setting-safe.html" >安全管理</a></dd>
						</dl>
                    </div>
                </div>
                <!--右侧主内容-->
                <div class="yui3-u-5-6 order-pay">
                    <div class="body">
                        <div class="choose-order">
                            <div class="sui-pagination pagination-large top-pages">
                                <ul>
                                    <li class="prev" v-if="query.page!=1"><a href="#" @click.prevent="prePage()">上一页</a></li>
                                    <li class="next" v-if="query.page!=tPages"><a href="#" @click.prevent="postPage()">下一页</a></li>
                                </ul>
                            </div>
                        </div>
                        <div class="table-title">
                            <table class="sui-table  order-table">
                                <tr>
                                    <thead>
                                    <th width="35%">宝贝</th>
                                    <th width="5%">单价</th>
                                    <th width="5%">数量</th>
                                    <th width="8%">商品操作</th>
                                    <th width="10%">实付款</th>
                                    <th width="10%">交易状态</th>
                                    <th width="10%">交易操作</th>
                                    </thead>
                                </tr>
                            </table>
                        </div>
                        <div class="order-detail">
                            <div class="orders">

                                <!--order1-->
                                <div v-for="(o, i) in orders" :key="i">
                                    <div class="choose-title">
                                        <label data-toggle="checkbox" class="checkbox-pretty ">
                                            <input type="checkbox" checked="checked" />
                                            <span>{{formatDate(o.createTime)}}　订单编号：{{o.orderId}} <a>联系客服</a></span>
                                        </label>
                                        <a class="sui-btn btn-info share-btn">分享</a>
                                    </div>
                                    <table class="sui-table table-bordered order-datatable">
                                        <tbody>
                                        <tr v-for="(d,j) in o.detailList" :key="j">
                                            <td width="35%">
                                                <div class="typographic"><img width="70px" height="70px" :src="d.image"/>
                                                    <a href="#" class="block-text">包邮 {{d.title}}</a>
                                                    <span class="guige" v-for="(v,k) in JSON.parse(d.ownSpec)" :key="k">{{k+':'+ v}}</span>
                                                </div>
                                            </td>
                                            <td width="5%" class="center">
                                                <ul class="unstyled">
                                                    <li>¥{{formatPrice(parseInt(d.price))}}</li>
                                                </ul>
                                            </td>
                                            <td width
                                                        ="5%" class="center">{{d.num}}</td>
                                            <td width="8%" class="center" :rowspan="o.detailList.length" v-if="j === 0">
                                                <ul class="unstyled" v-if="o.status >= 2 && o.status <= 6">
                                                    <li v-if="o.status === 2" >未发货</li>
                                                    <li v-if="o.status === 3" >已发货</li>
                                                    <li v-if="o.status === 2||o.status === 3 "><a>退货/退款</a></li>
                                                    <li v-if="o.status === 4 "><a>申请售后</a></li>
                                                </ul>
                                            </td>
                                            <td width="10%" class="center" :rowspan="o.detailList.length" v-if="j === 0">
                                                <ul class="unstyled">
                                                    <li>¥{{formatPrice(getTotalPrice(o))}}</li>
                                                    <li>（含运费：￥0.00）</li>
                                                </ul>
                                            </td>
                                            <td width="10%" class="center" :rowspan="o.detailList.length" v-if="j === 0">
                                                <ul class="unstyled">
                                                    <li v-if="o.status === 1">等待买家付款</li>
                                                    <li v-if="o.status === 2">已付款</li>
                                                    <li v-if="o.status === 3">已发货</li>
                                                    <li v-if="o.status === 4">已签收</li>
                                                    <li v-if="o.status === 8">失效订单</li>
                                                    <li><a href="home-orderDetail.html" class="btn">订单详情 </a></li>
                                                </ul>
                                            </td>
                                            <td width="10%" class="center" :rowspan="o.detailList.length" v-if="j === 0">
                                                <ul class="unstyled">
                                                    <li v-if="o.status === 1">{{timeFormatA(payTimes[d.skuId]-ATime,d.skuId)}}</li>
                                                    <li v-if="o.status === 1 && (payTimes[d.skuId]-ATime>0)" :class="d.skuId"><a href="#" @click.prevent="updateStatus(o.status,o.orderId)" class="sui-btn btn-info">立即付款</a></li>
                                                    <li v-if="o.status === 3">{{timeFormatA(sendTimes[d.skuId]-ATime,d.skuId)}}</li>
                                                    <li v-if="o.status === 2"><a href="#"  @click.prevent="updateStatus(o.status,o.orderId)" class="sui-btn btn-info">提醒发货</a></li>
                                                    <li v-if="o.status === 3 "><a href="#" @click.prevent="updateStatus(o.status,o.orderId)" class="sui-btn btn-info">确认收货</a></li>
                                                    <li v-if="o.status === 4">未评价</li>
                                                    <li v-if="o.status === 4 "><a href="#" @click.prevent="updateStatus(o.status,o.orderId)" class="sui-btn btn-info">评价</a></li>
                                                    <li v-if="o.status === 7">支付过期</li>
                                                    <li v-if="o.status === 7 "><a href="#" @click.prevent="updateStatus(o.status,o.orderId)" class="sui-btn btn-info">重新支付</a></li>
                                                    <li v-if="o.status === 8 "><a href="#" @click.prevent="updateStatus(o.status,o.orderId)" class="sui-btn btn-info">删除订单</a></li>
                                                    <!--                                            <li v-if="payTimes[d.skuId]-ATime>0" ><a href="javascript:void(0)" @click.prevent="deleteOrder(o.orderId)">订单已完成</a></li>-->
                                                </ul>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="choose-order">
                                <div class="sui-pagination pagination-large top-pages">
                                    <ul>
                                        <li class="prev" v-if="query.page!=1"><a href="#" @click.prevent="prePage()">«上一页</a></li>
                                        <li v-for="i in tPages"  :class="{'active':i==query.page}"><a href="#" @click.prevent="pSkip(i)">{{i}}</a></li>
                                        <!--                                    <li class="active"><a href="#">1</a></li>-->
                                        <!--                                    <li><a href="#">2</a></li>-->
                                        <!--                                    <li><a href="#">3</a></li>-->
                                        <li class="dotted"><span v-if="tPages>3">...</span></li>
                                        <li class="next" v-if="query.page!=tPages"><a href="#" @click.prevent="postPage()">下一页»</a></li>
                                    </ul>
                                    <div><span>共{{tPages}}页&nbsp;</span><div v-if="tPages!=1"><span>
                                            到
                                            <input  type="text" class="page-num"><button class="page-confirm"
                                                                                         onclick="alert(1)">确定</button>
                                            页</span></div></div>
                                </div>
                            </div>

                            <div class="clearfix"></div>
                        </div>

                        <div class="like-title">
                            <div class="mt">
                                <span class="fl"><strong>热卖单品</strong></span>
                            </div>
                        </div>
                        <div class="like-list">
                            <ul class="yui3-g">
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike01.png" />
                                        </div>
                                        <div class="attr">
                                            <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                        </div>
                                        <div class="price">
                                            <strong>
											<em>¥</em>
											<i>3699.00</i>
										</strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有6人评价</i>
                                        </div>
                                    </div>
                                </li>
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike02.png" />
                                        </div>
                                        <div class="attr">
                                            <em>Apple苹果iPhone 6s/6s Plus 16G 64G 128G</em>
                                        </div>
                                        <div class="price">
                                            <strong>
											<em>¥</em>
											<i>4388.00</i>
										</strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有700人评价</i>
                                        </div>
                                    </div>
                                </li>
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike03.png" />
                                        </div>
                                        <div class="attr">
                                            <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                        </div>
                                        <div class="price">
                                            <strong>
											<em>¥</em>
											<i>4088.00</i>
										</strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有700人评价</i>
                                        </div>
                                    </div>
                                </li>
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike04.png" />
                                        </div>
                                        <div class="attr">
                                            <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                        </div>
                                        <div class="price">
                                            <strong>
											<em>¥</em>
											<i>4088.00</i>
										</strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有700人评价</i>
                                        </div>
                                    </div>
                                </li>

                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

	<!-- 底部栏位 -->
	<!--页面底部，由js动态加载-->
	<div class="clearfix footer"></div>
	<script type="text/javascript">$(".footer").load("foot.html");</script>
	<!--页面底部END-->
<script src="./js/vue/vue.js"></script>
<script src="./js/axios.min.js"></script>
<script src="./js/common.js"></script>
<script src="./js/plugins/jquery/jquery.cookie.js"></script>
<script type="text/javascript">
    var vm = new Vue({
        el: "#account",
        data: {
            user: {},
            orders:[],
            orderDetails:[],
            query:{
                status:0,
                page:1,
                rows:5
            },
            payTimes:{},
            sendTimes:{},
            ATime:10,
            deleteO:"",
            tPages:0,
            flag:true,
            flag:false
        },
        created() {
            this.findInformationStatus();
            //倒计时
            this.ATime=new Date().getTime();
            setInterval(()=>{
                this.ATime=new Date().getTime();
                //console.log(this.ATime/(1000*3600*24*10));
            },1000);
            var searchStr = location.search.substring(1);
            var searchJson= ly.parse(searchStr);
            //console.log(searchJson);
            this.query.status=searchJson.status||0;
            //console.log(this.query.status);
            this.query.page=searchJson.page||1;
            this.query.rows=searchJson.rows||5;
            // 有token，曾经登录过，查询用户信息
            ly.http.get("/auth/verify")
                .then(resp => {
                    this.user = resp.data;
                    // 查询订单信息
                    this.query.status = 1;
                    this.loadOrder();
                })
                .catch(() => {
                    // 去登录
                    this.gotoLogin();
                });
        },
        destroyed() {
            clearInterval();
        },
        methods: {
            findInformationStatus(){
                ly.http.get("/informain/findUserInformationStatus").then((response) => {
                    if (response.data==1){
                        this.flag=true;
                        this.flag1=false
                    } else{
                        this.flag=false;
                        this.flag1=true
                    }
                }).catch(() => {
                    alert("找不到用户信息");
                })
            },
            logout() {
                // 删除cookie中的token即可
                Cookies.remove("LY_TOKEN",{
                    path:"/",
                    domain:"leyou.com"
                });
                window.location = 'http://www.leyou.com'
            },
            gotoLogin() {
                window.location = "login.html?returnUrl=" + window.location;
            },
            loadOrder(){
                // 查询订单信息
                ly.http.get("/order/list?"+ ly.stringify(this.query))
                    .then(({data:{items,total,totalPage}}) => {
                        this.orders = items;
                        let nowTime=new Date();
                        this.tPages=parseInt(totalPage);
                        console.log(this.tPages);
                        this.orders.forEach(o=>{
                            if(o.status==1){
                                let create=new Date(o.createTime);
                                let remain=parseInt(create.getTime()+1000*3600*24*2);
                                //let remain=parseInt(create.getTime());
                                o.detailList.forEach(d=>{
                                    this.payTimes[d.skuId]=remain;
                                })
                            }
                            if (o.status==3){
                                let create=new Date(o.endTime);
                                let remain=parseInt(create.getTime()+1000*3600*24*5);
                                //let remain=parseInt(create.getTime());
                                o.detailList.forEach(d=>{
                                    this.sendTimes[d.skuId]=remain;
                                })
                            }
                        })
                    }).catch(() => this.orders = [])
            },
            formatDate:ly.formatDate,
            formatPrice: ly.formatPrice,
            getTotalPrice(order){
                return order.detailList.map(d => d.num * d.price).reduce((v1,v2) => v1 + v2, 0);
            },
            getPage(){
                let t=this.orders.length;
                let r=this.query.rows;
                return parseInt(t/r+1);
            },
            prePage(){
                if (this.query.page>1){
                    this.query.page=this.query.page-1;
                }
            },
            postPage(){
                let a=this.tPages;
                if (a>this.query.page){
                    let p=this.query.page+1;
                    this.query.page=p;
                }
                console.log("下一页")
            },
            timeFormatA(time,id){
                time=time/1000;
                let strTime="";
                d=parseInt(time/3600/24);
                h= parseInt(time/(60*60))%24 ;
                m= parseInt(time/(60))%60 ;
                s= parseInt(time%60);
                if (d>0){
                    strTime=d+"天"+h+"小时"+m+"分"+s+"秒";
                }else {
                    if (h>0){
                        strTime=h+"小时"+m+"分"+s+"秒";
                    }else {
                        if (m>0){
                            strTime=m+"分"+s+"秒";
                        }else {
                            strTime=s+"秒";
                        }
                    }
                }
                if (time<0){
                    if (this.deleteO.indexOf(id)<0){
                        this.deleteO=","+id
                    }
                    //console.log(this.deleteO[id]);
                    return strTime="订单已过期";
                }
                return strTime;
            },
            searchIds(id){
                console.log("timeoutIds:"+this.timeoutIds);
            },
            refreshTime(id){
                let i=id;
                setInterval((i)=>{
                    this.countDown(i)
                },1000)
                // console.log(id);
            },
            countDown(id) {

            },
            pSkip(page){
                this.query.page=page;
            },
            updateStatus(status,id){

                console.log(status);
                console.log(id);
                ly.http.get("/order/status/"+status+"/"+id).then((resp)=>{
                    console.log("修改状态status="+resp.data);
                }).catch(()=>{
                    console.log("修改失败")
                });
                this.loadOrder();
                window.location.reload();
            }
        },
        watch:{
            'query':{
                deep:true,
                handler(){
                    const paramsUrl=ly.stringify(this.query);
                    const newUrl=location.origin+location.pathname+"?"+paramsUrl;
                    window.history.replaceState(null,null,newUrl);
                    this.loadOrder();

                }
            },
            "deleteO":{
                handler(){
                    alert("后台执行删除已过期订单")
                }
            }
        }
    });
</script>
</html>